/**
 * 
 */
package cl.inmotion.support.bitacora.view.servlets.mantenedores.bitacora;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cl.inmotion.support.bitacora.dao.RegistroDAO;

/**
 * @author afarias
 * 
 */
@WebServlet("/RegistroDelete")
public class RegistroDelete extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		/** Se recupera el registro */
		RegistroDAO registro= new RegistroDAO();

		try {
			registro.remove();
		} catch (SQLException e) {
			req.setAttribute(
					"errorMsg",
					"Ha ocurrido un error en la BDD al intentar acceder a los registros de este usuario. Contacte al administrador o intentelo mas tarde.");
			req.getRequestDispatcher("/WEB-INF/jsp/bitacora/Registro.jsp")
					.forward(req, resp);
			return;
		}

		req.setAttribute("infoMsg",
				"El registro ha sido eliminado sin problemas");
		req.getRequestDispatcher("/registro").forward(req, resp);
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}
	
	

}
